<?php

 function getEntityImages($entity_id,$entity_type='',$count=1){
			
	return MyDB::$db->getArray("select * from site_galleries where entity_id='".(int)$entity_id."' AND entity_type=".(int)$entity_type." AND status=1 LIMIT $count");
}

function footerLinks($pos){
	
	$pages = MyDB::$db->getArray("select slug,title from page_content where position='".$pos."' and status=1 ");
	$str = '';
	if(count($pages)) {
		foreach($pages as $page)
			$str .= "<li><a href='"._SITE_URL.$page['slug'].'/'."' title='".$page['title']."'>".$page['title']."</a></li>";
	}
	return $str;
}

function breadcrumb($arr){
	$str = '<div class="breadcrum">';
	if(count($arr)){
	foreach($arr as $k => $v)
		$str .= "<a href='".$v."'>".$k."</a>".' > ';
	}
	return substr($str,0,-2).'</div>';
}

function getCountries(){
	
	return MyDB::$db->getArray("SELECT id, name as value from country_master where status =1");
}


function image_url($imgArr){
	
		extract($imgArr);
		//echo '<pre>';print_r($imgArr);
		$image = (strlen($image))?$image:'noimage.jpg';
		if($width != '')
				$width=" width='$width'";
			if($height != '')
				$height=" height='$height'";
		$file_path = _SHAADI_IMAGE_PATH.$type.'/'.$image;
		$file_thumbpath = _SHAADI_IMAGE_PATH.$type.'/'.$size.'/'.$image;
		if(file_exists($file_thumbpath)) { 
			//$size_arr = @getimagesize($file_thumbpath);
			
			return "<img alt='$title' title='$title' src='"._SHAADI_IMAGE_URL.$type.'/'.$size.'/'.$image."' border='0' $width $height  $class alt='$alt' />";
		}
		else if(file_exists($file_path)) {
			//$size_arr = @getimagesize($file_path);
			
			return "<img alt='$title' title='$title' src='"._SHAADI_IMAGE_URL.$type.'/'.$image."' $width $height border='0' $class alt='$alt' />";
		}
		else {
			$image = 'noimage.jpg';
			$file_path = _SHAADI_IMAGE_URL.$type.'/'.$size.'/'.$image;
			return "<img alt='$title' title='$title' src='$file_path' $width $height border='0' $class alt='$alt' />";
		}
}

function trimstr($str,$len) {

	return (strlen($str) > $len)?substr($str,0,$len).'..':$str;
}

function clean_url($str='') {
		$arr = array(' ','  ','   ','&','/',"'",'"',',');
		$arr1 = array('-','-','-',' and ','-','','','','-');
		return str_replace($arr,$arr1,$str);
}
function split_id($str='') {
		return $id = @end(explode('-',$str));
}

function generatePassword ($length = 8)	{
	
	  $password = "";
	  $possible = "0123456789bcdfghjkmnpqrstvwxyz"; 
	  $i = 0; 
	  while ($i < $length) { 
		$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
		if (!strstr($password, $char)) { 
		  $password .= $char;
		  $i++;
		}
	  }
	  return $password;
}

function getCities($country_id){
	
	return MyDB::$db->getArray("SELECT id, state_id, name as value from city_master where country_id=".(int)$country_id." and status =1");
}

function getWthemes(){
	
	return MyDB::$db->getArray("SELECT id, theme as value from wedding_theme_master where status =1");
}

function getVenueTypes(){
	
	return MyDB::$db->getArray("SELECT id, venue_type as value from venue_type_master where status =1 order by value");
}

function getCategories(){
	
	return MyDB::$db->getArray("SELECT id, name as value from category where status =1");
}

function displayCombo($arr, $id = ''){
	$str = '';
	for($i=0;$i<count($arr);$i++)
	{
		if($arr[$i]['id'] == $id)
		$selected="selected='selected'";
		else
		$selected='';
		$str.="<option value='".$arr[$i]['id']."' $selected>".$arr[$i]['value']."</option>";
	} 
	return $str;
}

function get_id_byname($column,$value,$table) {
	global $db;
	$arr=$db->GetRow("Select id from ".$table." where $column = '".$value."'");
	return $arr['id'];
}
function get_name_byid($column,$value,$table) {
	global $db;
	$arr=$db->GetRow("Select $column from ".$table." where id in(".$value.") limit 1");
	return $arr[$column];
}

function paging($total_record,$file_name,$rows_per_page = 3)
{
		global $_limit;
		if (isset($_REQUEST['page'])) {
			$pageno = $_REQUEST['page'];
		} 
		else {
			$pageno = 1;
		} 
		
		$numrows = $total_record;
		$totalPages = ceil($numrows/$rows_per_page);
		$pageno = (int)$pageno;
		if ($pageno < 1) {
		   $pageno = 1;
		} elseif ($pageno > $totalPages && $totalPages!=0) {
		   $pageno = $totalPages;
		}
		$_limit = ' LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
	
	// how many link pages to show
	$numLinks      = 10;

	if ($totalPages > 1) {	
	// print 'previous' link only if we're not
		// on page one
		if ($pageno > 1) {
			$page = $pageno - 1;
			if ($page > 1) {
				$prev = "<li class='bnone'><a href='$file_name"."page=$page'> <img src='"._SITE_URL."images/spacer.gif' alt='Next' class='previous' /> </a></li>";
			} else {
				$prev = "<li class='bnone'><a href='$file_name' > <img src='"._SITE_URL."images/spacer.gif' alt='Next' class='previous' />  </a></li>";
			}	
				
			#$first = " <li class='bg''><a  href='$self'>First</a></li> ";
		} else {
			$prev  = "<li class='bnone'> <img src='"._SITE_URL."images/spacer.gif' alt='Next' class='previous' /></li>"; // we're on page one, don't show 'previous' link
			$first = ''; // nor 'first page' link
		}
	
		// print 'next' link only if we're not
		// on the last page
		if ($pageno < $totalPages) {
			$page = $pageno + 1;
			$next = "<li class='bnone'><a href='$file_name"."page=$page' > <img src='"._SITE_URL."images/spacer.gif' alt='Next' class='next' /> </a></li>&nbsp;&nbsp;";
		#	$last = "<li class='bg''> <a  href='$self&page=$totalPages'>Last</a></li> ";
		} else {
			$next = "<li class='bnone'> <img src='"._SITE_URL."images/spacer.gif' alt='Next' class='next' /> </li>&nbsp;&nbsp;"; // we're on the last page, don't show 'next' linkPre
			$last = ''; // nor 'last page' link
		}
		if(($pageno % $numLinks) == 0)
		$start = $pageno - (($pageno - 1) % $numLinks);
		else
		$start = $pageno - ($pageno % $numLinks )+ 1 ;
		$end   = $start + $numLinks - 1;		
		
		$end   = min($totalPages, $end);
		$pagingLink = array();
		for($page = $start; $page <= $end; $page++)	{
			if ($page == $pageno) {
				$pagingLink[] = "<li class='selected'>$page</li>";   // no need to create a link to current page
			} else {
				if ($page == 1 && $page == $pageno) {
					$pagingLink[] = "<li><a href='$file_name'>$page</a><li>";
				} else {	
					$pagingLink[] = "<li><a href='$file_name"."page=$page'>$page</a></li>";
				}	
			}
	
		}
		
		$pagingLink = implode(' ', $pagingLink);
		if ($totalPages > $end)
		{
			$tpages="<li> ... <a href='$file_name"."page=$totalPages'>$totalPages</a></li>";
		}
		if($pageno > $numLinks)
		{
			$fpage="<li><a href='$file_name'>1</a> ... </li>";
		}
		// return the page navigation link
		//$pagingLink = $first . $prev . $pagingLink . $next . $last;
		$pagingLink = $prev .$fpage. $pagingLink .$tpages. $next ;
	}
	
	return $pagingLink;
}				
?>